package com.wang.mandkey;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.wang.mandkey.activity.WelComeActivity;
import com.wang.mandkey.net.ConnecterPool;
import com.wang.mandkey.tool.MediaTool;
import com.wang.mandkey.utils.ProjectEnvironment;
import com.waps.AppConnect;

public class App extends Application {

	public static int screenHeight = 0;
	public static int screenWidth = 0;
	private static App instace;
	public ArrayList<Activity> activitsList;
	public static AppConnect appConnect;
	private String tag = "wangzyapp";

	@Override
	public void onCreate() {
		super.onCreate();
		Log.i(tag, "app create:" + hashCode());
		instace = this;
		activitsList = new ArrayList<Activity>();
		MediaTool.init();
	}

	public static App getInstance() {
		return instace;
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
		MediaTool.release();
	}

	public void doExit() {
		try {
			ConnecterPool.clearPool();
			AppConnect instance = AppConnect.getInstance(this);
			instance.finalize();
		} catch (Exception e) {
			e.printStackTrace();
		}

		ProjectEnvironment.isExit = true;
		for (Activity act : ProjectEnvironment.globalActivitys) {
			if (null != act) {
				try {
					act.finish();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}

		android.os.Process.killProcess(android.os.Process.myPid());

	}

	public static void exitApp(Context act) {
		Intent i = new Intent();
		i.setClass(act, WelComeActivity.class);
		i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		i.putExtra("flag", 0);
		act.startActivity(i);

	}

	public static AppConnect getAppConnect() {
		return appConnect;
	}

	public static void setAppConnect(AppConnect apc) {
		appConnect = apc;
	}
}
